TableView Setcion¶
TableView的Section就是在TableView头部显示一个标题,Section只是简单的自定义View 做完自定义View后在TableView的delegate中实现以下方法
1 2 3 4 | func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{ return TableViewSection(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 30)) //返回了一个名为TableViewSection的自定义view,并将坐标设为0,0,宽度为tableView的宽度,高度为30 } |
将自定义View返回即可,可以实现以下方法设置section高度
1 2 3 | func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> UIView?{ return 30 } |
其中section参数可以区分是第几个section,以便为不同的部分显示不同的标题